package com.foton.mybatis.session;

import cn.hutool.core.collection.CollectionUtil;
import com.foton.mybatis.configration.Configration;
import com.foton.mybatis.eunm.SqlType;
import com.foton.mybatis.excuter.Excuter;
import com.foton.mybatis.excuter.SimpleExcuter;

import java.util.List;

/**
 * @Author RenPu
 * @Date 2023/3/29 17:55
 * @Version 1.0
 * @Description:
 **/
public class DefaultSqlSession implements SqlSession {

    private final Configration configration;
    private final Excuter excuter;

    public DefaultSqlSession(Configration configration) {
        this.configration = configration;
        this.excuter = new SimpleExcuter(this.configration);
    }




    @Override
    public <T> T selectOne(String statemetId, Object parameter) {

        List<T> resultList = this.<T>selectList(statemetId, parameter);
        if(CollectionUtil.isNotEmpty(resultList)&&resultList.size()>1){
            throw new IllegalArgumentException("should one resultSet, but return too many now please check !!!!!");
        }
        return resultList.get(0);
    }

    @Override
    public <T> List<T> selectList(String statemetId, Object parameter) {
        return null;
    }

    @Override
    public <T> T getMapper(Class<T> type) {
        return configration.<T>getMapper(type,this);
    }

    @Override
    public Configration getConfigration() {
        return this.configration;
    }

    @Override
    public void upate(String stamentedId, Object[] args) {

    }


}
